import 'package:easy_refresh/easy_refresh.dart';
import 'package:flutter/material.dart';
import 'package:flutter_chat/common/style/styles.dart';
import 'package:flutter_chat/common/widget/widgets.dart';
import 'package:flutter_chat/pages/application/pages/contacts/widget/info.dart';
import 'package:get/get.dart';

import 'logic.dart';

class GroupListPage extends GetView<GroupListLogic> {
  const GroupListPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: customAppBar("群聊(5)"),
      body: _buildEasyRefresh(),
    );
  }

  /// 列表
  ListView _buildListView(ScrollPhysics physics) {
    return ListView.separated(
      physics: physics,
      itemBuilder: (context, index) {
        return Info(
          avatar: Container(
            width: 35,
            height: 35,
            decoration: BoxDecoration(
              color: Colors.green,
              borderRadius: BorderRadius.circular(
                AppTheme.radius,
              ),
            ),
            child: const Icon(
              Icons.group_rounded,
              color: Colors.white,
            ),
          ),
          title: "群聊$index",
          onTap: () {},
        );
      },
      separatorBuilder: (context, index) {
        return const Divider(height: 1);
      },
      itemCount: 5,
    );
  }

  /// 下拉刷新
  EasyRefresh _buildEasyRefresh() {
    return EasyRefresh.builder(
      header: CustomClassic().getHeader(),
      footer: CustomClassic().getFooter(),
      onRefresh: () async {
        await Future.delayed(const Duration(seconds: 2));
      },
      childBuilder: (context, physics) {
        return _buildListView(physics);
      },
    );
  }
}
